package com.fsserver.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 支付宝支付配置类
 */
@Configuration
public class AlipayConfig {

    /**
     * 支付宝网关
     */
    @Value("${alipay.gateway}")
    private String gateway;

    /**
     * 应用ID
     */
    @Value("${alipay.appId}")
    private String appId;

    /**
     * 应用私钥
     */
    @Value("${alipay.privateKey}")
    private String privateKey;

    /**
     * 支付宝公钥
     */
    @Value("${alipay.alipayPublicKey}")
    private String alipayPublicKey;

    /**
     * 签名类型
     */
    @Value("${alipay.signType:RSA2}")
    private String signType;

    /**
     * 字符编码
     */
    @Value("${alipay.charset:UTF-8}")
    private String charset;

    /**
     * 数据格式
     */
    @Value("${alipay.format:json}")
    private String format;

    /**
     * 支付结果通知地址
     */
    @Value("${alipay.notifyUrl}")
    private String notifyUrl;

    /**
     * 支付成功返回地址
     */
    @Value("${alipay.returnUrl}")
    private String returnUrl;

    /**
     * 创建支付宝客户端
     */
    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(
                gateway, 
                appId, 
                privateKey, 
                format, 
                charset, 
                alipayPublicKey, 
                signType
        );
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public String getReturnUrl() {
        return returnUrl;
    }

    public String getAppId() {
        return appId;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public String getAlipayPublicKey() {
        return alipayPublicKey;
    }

    public String getSignType() {
        return signType;
    }

    public String getCharset() {
        return charset;
    }

    public String getFormat() {
        return format;
    }
} 